package com.neu.his.controller.SystemManage01.UserManage;

import com.neu.his.core.Result;
import com.neu.his.entity.User;
import com.neu.his.entity.VO.DeleteVO;
import com.neu.his.entity.VO.SystemManage01.UserManage.UserQueryVO;
import com.neu.his.entity.request.DeleteParams;
import com.neu.his.entity.request.UserManage.UserPageParams;
import com.neu.his.entity.request.UserManage.UserParams;
import com.neu.his.entity.request.UserManage.UserUpdateParams;
import com.neu.his.mapper.UserMapper;
import com.neu.his.service.UserService;
import com.neu.his.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Description: neu-his
 * <p>
 * Created by 31316 on 2020/7/16 20:53
 */
@RestController
@RequestMapping("/user")
public class UserManageController {
    @Autowired
    UserService userService;

    @Autowired
    UserMapper userMapper;

    @PostMapping
    public Result insertOne(@RequestBody UserParams userParams) {
        if (userService.insertOne(userParams)) {
            return Result.success();
        } else return Result.fail();
    }

    @PutMapping
    public Result updateOne(@RequestBody UserUpdateParams userUpdateParams) {
        if (userService.updateOne(userUpdateParams)) {
            return Result.success();
        } else return Result.fail();
    }

    @PostMapping("/query")
    public Result<PageList<UserQueryVO>> userQuery(@RequestBody UserPageParams userPageParams){
        PageList<UserQueryVO> pageList=userService.userQuery(userPageParams);
        return Result.success(pageList);
    }

    @DeleteMapping
    public Result<DeleteVO> deleteSome(@RequestBody DeleteParams deleteParams) {
        userMapper.deleteByIds(deleteParams.getIds());
        return Result.success(new DeleteVO());
    }

    @GetMapping("/all")
    public Result<List<UserQueryVO>> getall(){
        List<UserQueryVO> list = userService.getall();
        return Result.success(list);
    }

}
